<template>
  <div class="audio-player" @click="hidePlayer">
    <div class="player-container">
      <button class="el-icon-close" @click="hidePlayer"></button>
      <audio :src="audioUrl" controls ref="audioPlayer"></audio>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    audioUrl: {
      type: String,
      default: "",
    },
  },
  watch: {
    audioUrl(newUrl) {
      if (newUrl) {
        this.$refs.audioPlayer.src = newUrl;
        this.$refs.audioPlayer.play();
      }
    },
  },
  methods: {
    hidePlayer() {
      this.$emit("close");
    },
  },
};
</script>

<style scoped>
.audio-player {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.3);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.player-container {
  background-color: rgb(0 0 0 / 0%);
  padding: 50px;
  text-align: center;
  position: relative;
}

.el-icon-close {
  position: absolute;
  top: 0px;
  right: 0px;
  background-color: rgb(0, 0, 0);
  color: white;
  border: none;
  padding: 5px 10px;
  border-radius: 5px;
  cursor: pointer;
}

/* audio {
  width: 100%;
  max-width: 600px;
} */
</style>